$(function () {
    var fail_datagrid = $("#fail_datagrid");



    fail_datagrid.datagrid({
        fitColumns: true,
        fit: true,
        toolbar: '#fail_toolbar',
        url: '/fail/list.do?state=0',
        pagination: true,
        striped: true,
        rownumbers: true,
        singleSelect: true,
        columns: [[
            {title: '时间',align:"center", field: 'inputDate', width: '300'},
            {
                title: '客户' ,align:"center", field: 'client', width: '300', formatter: function (value, row, index) {
                    return value ? value.name : "<font color='red'>-----</font>"
                }
            },
            {
                title: '负责人',align:"center", field: 'principal', width: '300', formatter: function (value, row, index) {
                    return value ? value.realname : "<font color='red'>-----</font>"
                }
            },
            { title: '移交原因',align:"center", field: 'failReason', width: '300' }
        ]]
    })




    var methodObj = {

        //刷新按钮
        reload: function () {
            fail_datagrid.datagrid("reload");
        },
        //清空高级查询条件
        clearQuery : function () {
            //清空高级查询数据
            $("#beginDate").datebox("setValue","");
            $("#endDate").datebox("setValue","");
            $("#qoClient").textbox("setValue","");
            $("#qoPrincipal").textbox("setValue","");
            //关闭高级查询div
            $("#queryObject").hide();
            $("#queryObject").data("num", 1);
            //重新加载数据表格
            fail_datagrid.datagrid('reload',{});
        },
        //高级查询
        query:function () {
            var beginDate = $("#beginDate").textbox("getValue");
            var endDate = $("#endDate").textbox("getValue");
            var qoPrincipal = $("#qoPrincipal").textbox("getValue");
            var qoClient = $("#qoClient").textbox("getValue");

            fail_datagrid.datagrid('load', {
                beginDate: beginDate,
                endDate: endDate,
                principal: qoPrincipal,
                client: qoClient,
            });
        }
    }


    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    })

})

